package com.aso114.project.mvp.model;

import android.text.TextUtils;
import android.util.Log;

import com.aso114.project.base.BaseApplication;
import com.aso114.project.base.BaseBean;
import com.aso114.project.base.BaseModel;
import com.aso114.project.bean.BannerBean;
import com.aso114.project.bean.CityInfoBean;
import com.aso114.project.bean.H5Entity;
import com.aso114.project.bean.HistoryBean;
import com.aso114.project.bean.Login;
import com.aso114.project.bean.LoginBean;
import com.aso114.project.bean.NeednoticeBean;
import com.aso114.project.bean.News;
import com.aso114.project.bean.PhoneBean;
import com.aso114.project.bean.QuestionBean;
import com.aso114.project.bean.QuestionUserListBean;
import com.aso114.project.bean.TrueQuestionBean;
import com.aso114.project.bean.UserInfoBean;
import com.aso114.project.bean.VerificationCodeBean;
import com.aso114.project.exam.QuestionTestActivity;
import com.aso114.project.mvp.LoginSP;
import com.aso114.project.util.Constant;
import com.aso114.project.util.Helper;
import com.aso114.project.util.MD5Util;
import com.aso114.project.util.rxjava.ApiCallback;
import com.aso114.project.util.rxjava.SubscriberCallBack;
import com.google.gson.Gson;


import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;


/**
 * username:Created by hsj on 2016/10/11 0011.
 * class：
 * 类描述：公共接口
 */

public class CommentModel extends BaseModel implements ICommentModel {

    private static CommentModel commentModel = null;

    private CommentModel() {
    }

    public static CommentModel getInstant() {
        if (null == commentModel) {
            commentModel = new CommentModel();
        }
        return commentModel;
    }

    @Override
    public void getPhone(String mobile, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "member");
        tMap.put("h", "chenkmobile");
        tMap.put("mobile", mobile);
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", Constant.CateId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.getPhone(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<PhoneBean>>() {
            @Override
            public void onSuccess(BaseBean<PhoneBean> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    @Override
    public void getVerificationCode(String mobile, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "verify");
        tMap.put("h", "sendcode");
        tMap.put("mobile", mobile);
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", Constant.CateId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //把参数传进Map中

        FormBody.Builder builder = new FormBody.Builder();
        for (String key : tMap.keySet()) {
            //追加表单信息
            builder.add(key, tMap.get(key));
        }

        RequestBody formBody = builder.build();
        addSubscription(apiStores.getVerificationCode(formBody), new SubscriberCallBack<>(new ApiCallback<BaseBean<VerificationCodeBean>>() {
            @Override
            public void onSuccess(BaseBean<VerificationCodeBean> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    //登陆
    @Override
    public void getLogin(String mobile, String code, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "member");
        tMap.put("h", "userlogin");
        tMap.put("mobile", mobile);
        tMap.put("code", code);
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", Constant.CateId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //把参数传进Map中

        FormBody.Builder builder = new FormBody.Builder();
        for (String key : tMap.keySet()) {
            //追加表单信息
            builder.add(key, tMap.get(key));
        }

        RequestBody formBody = builder.build();

        addSubscription(apiStores.getLogin(formBody), new SubscriberCallBack<>(new ApiCallback<BaseBean<LoginBean>>() {
            @Override
            public void onSuccess(BaseBean<LoginBean> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    //个人信息
    @Override
    public void getUserInfo(String usertoken, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "member");
        tMap.put("h", "userinfo");
        tMap.put("token", usertoken);
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", Constant.CateId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.getUserInfo(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<UserInfoBean>>() {
            @Override
            public void onSuccess(BaseBean<UserInfoBean> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    //个人信息
    @Override
    public void setUserInfo(String pic, String name, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "member");
        tMap.put("h", "setUserInfo");
        tMap.put("type", "1");
        if (!TextUtils.isEmpty(pic)) {
            tMap.put("userLitpic", pic);
        }
        if (!TextUtils.isEmpty(name)) {
            tMap.put("userName", name);
        }
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", Constant.CateId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //把参数传进Map中

        FormBody.Builder builder = new FormBody.Builder();
        for (String key : tMap.keySet()) {
            //追加表单信息
            builder.add(key, tMap.get(key));
        }

        RequestBody formBody = builder.build();

        addSubscription(apiStores.setUserInfo(formBody), new SubscriberCallBack<>(new ApiCallback<BaseBean<UserInfoBean>>() {
            @Override
            public void onSuccess(BaseBean<UserInfoBean> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //选择考区接口
    @Override
    public void getCityInfo(final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "area");
        tMap.put("h", "arealist");
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", Constant.CateId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.getCityInfo(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<List<CityInfoBean>>>() {
            @Override
            public void onSuccess(BaseBean<List<CityInfoBean>> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //行测与申论banner接口
    @Override
    public void getAptiudeTest_banner(String bannerid,String adType, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "advert");
        tMap.put("h", "getadlist");
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("adType", adType);
        tMap.put("CateId", bannerid);//Constant.adutst
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.getaptiude_banner(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<List<BannerBean>>>() {
            @Override
            public void onSuccess(BaseBean<List<BannerBean>> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    //真题模考各类别接口
    @Override
    public void get_true_quewtion(final int page, String type, String CateId, final CallBack
            callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "paper");
        tMap.put("h", "getlist");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("page", String.valueOf(page));
        tMap.put("type", type);
        System.out.println("城市id===" + LoginSP.getInstance().getUserAreaId());
        tMap.put("AreaId", LoginSP.getInstance().getUserAreaId());//LoginSP.getInstance()
        // .getUserAreaId()
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", CateId);//Constant.adutst
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.get_true_question(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<List<TrueQuestionBean>>>() {
            @Override
            public void onSuccess(BaseBean<List<TrueQuestionBean>> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    @Override
    public void getSpecialTreeList(String cateid,final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "special");
        tMap.put("h", "GetSpecialTreeList");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", cateid);
        tMap.put("SpecialId", Constant.SpecidlId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.getSpecialTreeList(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<List<QuestionUserListBean>>>() {
            @Override
            public void onSuccess(BaseBean<List<QuestionUserListBean>> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //保存考区ID接口
    @Override
    public void get_save_arid(final String arayid, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "member");
        tMap.put("h", "setUserInfo");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("type", "1");
        tMap.put("userAreaId", arayid);
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", Constant.CateId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.get_save_arid(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //获取行测或申论题库
    @Override
    public void get_question_bank(final String AreaId, String PaperId, String catid, final
    CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "paper");
        tMap.put("h", "getPaperQuestionList");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("PaperId", PaperId);

        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("AreaId", AreaId);
        tMap.put("CateId", catid);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.get_question_bank(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<QuestionBean>>() {
            @Override
            public void onSuccess(BaseBean bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //获取须知内容接口
    @Override
    public void getneedcontect(final String id, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "news");
        tMap.put("h", "getInfo");
        tMap.put("token", LoginSP.getInstance().getToken());

        tMap.put("Id", id);
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.getneedcontect(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<NeednoticeBean>>() {
            @Override
            public void onSuccess(BaseBean<NeednoticeBean> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //提交试卷
    @Override
    public void post_paper(String paperid, String testtype,String PaperSorce, final String json, final CallBack
            callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "paper");
        tMap.put("h", "setUserPaperQuestion");
        tMap.put("token", LoginSP.getInstance().getToken());

        tMap.put("datainfo", URLEncoder.encode(json));
        tMap.put("PaperId", paperid);
        tMap.put("PaperSorce", PaperSorce);//总分
        tMap.put("PaperType", Constant.title_tv);//1,//考点、随机、专项练习 2,//章节 3,//真题 4,//巩固
        tMap.put("PaperTime", String.valueOf(QuestionTestActivity.currentTime));//总时间
        tMap.put("PaperTestType", testtype);//1是交卷 9是保存练习

        System.out.println("paperid=====" + paperid);
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("AreaId", LoginSP.getInstance().getUserAreaId());
        tMap.put("CateId", Constant.adutst);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //把参数传进Map中

        FormBody.Builder builder = new FormBody.Builder();
        for (String key : tMap.keySet()) {
            //追加表单信息
            builder.add(key, tMap.get(key));
        }

        RequestBody formBody = builder.build();

        addSubscription(apiStores.post_paper(formBody), new SubscriberCallBack<>(new ApiCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    // 提交收藏
    @Override
    public void setCollect(String cateId, String realQuestionId, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "collect");
        tMap.put("h", "setCollect");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", cateId);
        tMap.put("AreaId", LoginSP.getInstance().getUserAreaId());
        tMap.put("RealQuestionId", realQuestionId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //把参数传进Map中

        FormBody.Builder builder = new FormBody.Builder();
        for (String key : tMap.keySet()) {
            //追加表单信息
            builder.add(key, tMap.get(key));
        }

        RequestBody formBody = builder.build();
        addSubscription(apiStores.setCollect(formBody), new SubscriberCallBack<>(new ApiCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    // 删除收藏
    @Override
    public void delCollect(String cateId, String questionId, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "collect");
        tMap.put("h", "delCollect");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", cateId);
        tMap.put("AreaId", LoginSP.getInstance().getUserAreaId());
        tMap.put("QuestionId", questionId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //把参数传进Map中

        FormBody.Builder builder = new FormBody.Builder();
        for (String key : tMap.keySet()) {
            //追加表单信息
            builder.add(key, tMap.get(key));
        }

        RequestBody formBody = builder.build();
        addSubscription(apiStores.delCollect(formBody), new SubscriberCallBack<>(new ApiCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    // 获取收藏列表
    @Override
    public void getCollect(String cateId, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "collect");
        tMap.put("h", "getlist");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", cateId);
        tMap.put("AreaId", LoginSP.getInstance().getUserAreaId());
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.getCollect(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<QuestionBean>>() {
            @Override
            public void onSuccess(BaseBean<QuestionBean> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //获取章节练习题库
    @Override
    public void get_chapter_bank(final String AreaId, String SpecialId, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "paper");
        tMap.put("h", "FastIntelligentPaper");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("SpecialId", SpecialId);

        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("AreaId", AreaId);
        tMap.put("CateId", Constant.adutst);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.get_chapter_bank(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<QuestionBean>>() {
            @Override
            public void onSuccess(BaseBean bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //获取练习历史列表
    @Override
    public void get_history_list(int papge, final String AreaId, String CateId, String status, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "member");
        tMap.put("h", "getHistoryList");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("Page", String.valueOf(papge));
        tMap.put("Status", status);

        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("AreaId", AreaId);
        tMap.put("CateId", CateId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.get_history_list(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<HistoryBean>>() {
            @Override
            public void onSuccess(BaseBean<HistoryBean> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }

//                    List<HistoryBean> data =  (List<HistoryBean>)bean.getData().getData();
//                    System.out.println("练习历史数组大小==="+data.size() );
                    callBack.onSuccess(bean.getData().getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //获取练习历史题库
    @Override
    public void get_history_bank(final String AreaId, String paperId, String catid, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "paper");
        tMap.put("h", "getAutoPaperInfo");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("PaperId", paperId);

        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("AreaId", AreaId);
        tMap.put("CateId", catid);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.get_history_bank(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<QuestionBean>>() {
            @Override
            public void onSuccess(BaseBean bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //获取成绩列表
    @Override
    public void get_result_list(int papge, final String AreaId, String CateId, String status, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "member");
        tMap.put("h", "getHistoryList");
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("Page", String.valueOf(papge));
        tMap.put("Status", status);
        tMap.put("PaperType", "3,4");
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("AreaId", AreaId);
        tMap.put("CateId", CateId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.get_result_list(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<HistoryBean>>() {
            @Override
            public void onSuccess(BaseBean<HistoryBean> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }

//                    List<HistoryBean> data =  (List<HistoryBean>)bean.getData().getData();
//                    System.out.println("练习历史数组大小==="+data.size() );
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    //获取考点练习题库
    @Override
    public void get_testing_bank(final String AreaId, String catid, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "paper");
        tMap.put("h", "SpecialExercisePaper");
        tMap.put("token", LoginSP.getInstance().getToken());

        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("AreaId", AreaId);
        tMap.put("CateId", catid);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.get_testing_bank(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<QuestionBean>>() {
            @Override
            public void onSuccess(BaseBean bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    // 错题练习
    @Override
    public void geterror_exercise(int page, String cateId, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "member");
        tMap.put("h", "getErrorList");
        tMap.put("Page", String.valueOf(page));
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", cateId);
        tMap.put("AreaId", LoginSP.getInstance().getUserAreaId());
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        addSubscription(apiStores.get_error_exercise(tMap), new SubscriberCallBack<>(new ApiCallback<BaseBean<QuestionBean>>() {
            @Override
            public void onSuccess(BaseBean<QuestionBean> bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


    @Override
    public void del_error_topic(String questionId, String paperid, String cateid, final CallBack callBack) {
        Map<String, String> tMap = new HashMap<String, String>();
        tMap.put("v", Constant.vison);
        tMap.put("f", "member");
        tMap.put("h", "deleteError");
        tMap.put("PaperId", paperid);
        tMap.put("token", LoginSP.getInstance().getToken());
        tMap.put("t", Helper.getStringDate());
        tMap.put("appkey", Constant.appkey);
        tMap.put("CateId", cateid);
        tMap.put("AreaId", LoginSP.getInstance().getUserAreaId());
        tMap.put("QuestionId", questionId);
        try {
            tMap.put("sign", MD5Util.getSignature(Helper.getSign(tMap), Constant.sign));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //把参数传进Map中

        FormBody.Builder builder = new FormBody.Builder();
        for (String key : tMap.keySet()) {
            //追加表单信息
            builder.add(key, tMap.get(key));
        }

        RequestBody formBody = builder.build();
        addSubscription(apiStores.del_error(formBody), new SubscriberCallBack<>(new ApiCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                boolean isSuccess = false;
                if (bean.getCode() == 200 || bean.getCode() == 1005) {
                    if (bean.getCode() == 200) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                    callBack.onSuccess(bean.getData(), isSuccess, bean.getMessage());

                } else {
                    callBack.onFailure(bean.getMessage());
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                callBack.onFailure(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }


}

